package frank.zou;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
//import org.apache.log4j.Logger;
import org.springframework.web.context.WebApplicationContext;

import com.opensymphony.xwork.ActionSupport;

public class SignonAction extends ActionSupport {
	private UserInfo userInfo; 
	private UserService userService; 

//	private static Logger log = Logger.getLogger("frank.zou.SignonAction.class");
	private static Log log = LogFactory.getLog("frank.zou.SignonAction.class");
	
	public String execute() throws Exception {
		if (log.isDebugEnabled()) { 
			log.debug("into SignonAction.execute()");
		}
		if (validatedUser(userInfo.getName(), userInfo.getPassword())) { 
			return SUCCESS; 
		} else { 
			return ERROR; 
		}
	}

	private boolean validatedUser(String name, String password) {
		// TODO Auto-generated method stub
		
//		UserService userService = new UserServiceImpl(); 
		return getUserService().validateUser(name, password);
	}
	
	private UserService getUserService() { 
//		WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext();
//		return (UserService)ctx.getBean("");
		return this.userService;
	}

	public UserInfo getUserInfo() {
		return userInfo;
	}

	public void setUserInfo(UserInfo userInfo) {
		this.userInfo = userInfo;
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}
}
